package org.mozhu.mboot.core.social.github.config;

import org.mozhu.mboot.core.social.SecurityConstants;
import org.mozhu.mboot.core.social.SocialConnectView;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.autoconfigure.SocialAutoConfigurerAdapter;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.social.github.connect.GitHubConnectionFactory;
import org.springframework.web.servlet.View;

@Configuration
public class GithubAuthConfiguration extends SocialAutoConfigurerAdapter {

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        return new GitHubConnectionFactory(SecurityConstants.DEFAULT_SOCIAL_GITHUB_CLIENT_ID, SecurityConstants.DEFAULT_SOCIAL_GITHUB_CLIENT_SECRET);
    }

    /**
     * /connect/weixin POST请求,绑定微信返回connect/weixinConnected视图
     * /connect/weixin DELETE请求,解绑返回connect/weixinConnect视图
     *
     * @return
     */
    @Bean({"connect/githubConnect", "connect/githubConnected"})
    @ConditionalOnMissingBean(name = "githubConnectedView")
    public View githubConnectedView() {
        return new SocialConnectView();
    }

}
